package com.ruoyi.web.pojo.request.insect;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.net.url.UrlBuilder;
import com.ruoyi.common.utils.CommonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public class InsectCountDataRequest {

    @ApiModelProperty(value = "数据开始时间,格式 yyyy-MM-dd")
    private String startTime;

    @ApiModelProperty(value = "数据结束时间")
    private String endTime;

    @ApiModelProperty(value = "日期类型，1 全部，2 本年 , 3 本月 , 4 本周")
    private Integer dateType = 1;

    @ApiModelProperty("昆虫类型 1 一类害虫 2 二类害虫 3 其他 全部不传")
    private Integer insectType;

    @ApiModelProperty(value = "设备ID集合")
    private List<String> deviceIds;

    public void setEndTime(String endTime) {
        if(endTime != null){
            this.endTime = CommonUtils.computeTime(endTime,1);
        }
    }

    public void buildDefTime(String endTime) {
        this.setEndTime(endTime);
        this.startTime = CommonUtils.computeTime(endTime,-15);
    }

    public InsectSumDataRequest buildRequest(){
        InsectSumDataRequest request = new InsectSumDataRequest();

        request.setStartTime(startTime);
        request.setEndTime(endTime);
        request.setDeviceIds(deviceIds);

        return request;
    }


    public UrlBuilder getQuery(){
        UrlBuilder builder = UrlBuilder.of();
        if (CollUtil.isNotEmpty(deviceIds)){
            builder.addQuery("deviceId",this.getDeviceIds().stream().collect(Collectors.joining(",")));
        }
        if (this.getInsectType() != null)builder.addQuery("insectType",this.getInsectType());
        builder.addQuery("dateType",this.getDateType());
        if (this.getStartTime() != null) builder.addQuery("startTime",this.getStartTime());
        if (this.getEndTime() != null) builder.addQuery("endTime",this.getEndTime());

        return builder;
    }


}
